﻿#region Copyright and License
/*==============================================================================
 *  Copyright (c) www.51mvc.com Corporation.  All rights reserved.
 * ===============================================================================
 * This code and information is provided "as is" without warranty of any kind,
 * either expressed or implied, including but not limited to the implied warranties
 * of merchantability and fitness for a particular purpose.
 * ===============================================================================
 * Licensed under the GNU General Public License (GPL) v2
 * http://www.51mvc.com/
 * Create By 小鱼(Leven)  - http://leven.com.cn
 * ==============================================================================*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Infancy.Core.Entities;

namespace Infancy.Core.Repository {
    /// <summary>
    /// 数据层基本组件接口
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public interface IRepository<TEntity> where TEntity : IEntity {
        #region simple GUID method

        /// <summary>
        /// 插入一条数据
        /// </summary>
        /// <param name="entity">数据实体</param>
        void Insert(TEntity entity);

        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="entity">数据实体</param>
        void Update(TEntity entity);

        /// <summary>
        /// 删除指定的实体数据(以ID为准)
        /// </summary>
        /// <param name="entity">实体数据</param>
        void Delete(TEntity entity);

        /// <summary>
        /// 删除指定的数据
        /// </summary>
        /// <param name="id">ID信息</param>
        void Delete(long id);

        /// <summary>
        /// 统计数据库中该表(类型)数据的总量
        /// </summary>
        /// <returns></returns>
        int Count();

        /// <summary>
        /// 获取单条数据
        /// </summary>
        /// <param name="id">id主键信息</param>
        /// <returns></returns>
        TEntity GetSingle(long id);

        /// <summary>
        /// 获取该表(类型)的所有数据,一般用于小表(类型)
        /// </summary>
        /// <returns></returns>
        IList<TEntity> GetList();

        /// <summary>
        /// 创建一个该表(类型)对应的默认实体
        /// </summary>
        /// <returns></returns>
        TEntity Create();

        #endregion
    }
}
